﻿#--------------------------------------------------------------------------------------------------------------------------------------------------------
#
# Mi-DevEnv			:	http://midevenv.codeplex.com 
#					:	(c) IT Bridge 2012
#					:	A concept originated by Chris Nurse
#
# Licence			:	GNU General Public License version 2 (GPLv2)
#					:	http://midevenv.codeplex.com/license
#
# Summary           :   This script prepares a windows image to automatically SysPrep at next boot
# Actions           :   Prepare machine as base drive template for future repeated use
#
#--------------------------------------------------------------------------------------------------------------------------------------------------------

Write-Host "Setup autlogon as Administrator"
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"

Set-ItemProperty $regPath -Name "AutoAdminLogon"    -Value "1" 
Set-ItemProperty $regPath -Name "DefaultDomainName" -Value ""
Set-ItemProperty $regPath -Name "DefaultUserName"   -Value "Administrator"
Set-ItemProperty $regPath -Name "DefaultPassword"   -Value "P@ssword1"

Write-Host "Set RunOnce key to start sysprep at reboot"
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
$command = "c:\Mi-DevEnv\MDE-Initialisation\PrepImage.Bat"

if (Test-Path $regPath) {
    Set-ItemProperty $regPath -Name "Mi-DevEnv" -Value $command
    }
else {
    New-Item $regPath | Out-Null
    New-ItemProperty $regPath -Name "Mi-DevEnv" -Value $command
    }

Write-Host
Write-Host "When the machine is rebooted it will automatically execute the SYSPREP process." -ForegroundColor Cyan
Write-Host
write-host "Shutting down in 10 seconds"
Start-Sleep -s 10
Stop-Computer 